<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('试卷列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>试卷名称：</label>
                            <input type="text" name="name"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="module:pager:add">
                <i class="fa fa-plus"></i> 添加考试
            </a>
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="module:pager:edit">-->
            <!--<i class="fa fa-edit"></i> 修改-->
            <!--</a>-->
            <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="module:pager:remove">-->
            <!--<i class="fa fa-remove"></i> 删除-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('module:pager:edit')}]];
    var removeFlag = [[${@permission.hasPermi('module:pager:remove')}]];
    var prefix = ctx + "module/pager";
    var datas = [[${@dict.getType('tb_pager_publish')}]];
    var s = [[${@dict.getType('tb_pager_status')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "试卷",
            detailView: true,
            showFooter: false,
            showToggle: false,
            showColumns: false,
            onExpandRow: function (index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '试卷名称',
                    width:700
                },
                {
                    field: 'ksTime',
                    title: '考试时间(分钟)'
                },
                {
                    field: 'score',
                    title: '总分',
                    visible:false
                },
                {
                    field: 'passScore',
                    title: '合格分数',
                    visible:false
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }

                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="lookPager(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看试卷</a> ');
                        if(row.status=='0'){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="start(\'' + row.id + '\')"><i class="fa fa-edit"></i>发布考试</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        actions.push('<a class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="rankPager(\'' + row.id + '\')"><i class="fa fa-edit"></i>试卷排序</a> ');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    initChildTable = function (index, row, $detail) {
        var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
        $(childTable).bootstrapTable({
            url: ctx + "module/pageruser/list",
            method: 'post',
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            queryParams: {
                pagerId: row.id
            },
            columns: [
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '考试对象名称'
                },
                {
                    field: 'pagerName',
                    title: '试卷名称'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(s, value);
                    }

                }]
        });
    };


    
    function start(id) {
        $.modal.confirm("确认发布考试吗？", function () {
            var url = prefix + "/edit";
            var data = {
                "id": id ,
                "status":"1"};
            $.operate.submit(url, "post", "json", data);
        })
    }
    
    function lookPager(id) {
        var url = prefix +"/lookPager/"+id;
        $.modal.openTab("试卷详情",url);
    }

    function rankPager(id) {
        var url = prefix +"/rankPager/"+id;
        $.modal.openTab("试卷排序",url);
    }
</script>
</body>
</html>